﻿using SqlSugar;

namespace My.Web.Model;

/// <summary>
/// 菜单
/// </summary>
/// AICFlowStatistics_T_Menu
[SugarTable("AICFlowStatistics_T_Menu")]//, TableDescription = "菜单"
public class Menu
{
    /// <summary>
    /// 菜单Id  类型哟啊和数据库的对的上，不然会报错
    /// </summary>
    [SugarColumn(IsPrimaryKey = true)]
    public string? MenuId { get; set; }


    //[SugarColumn(IsPrimaryKey = true)]
    //public string? MenuId2 { get; set; }

    /// <summary>
    /// 上级ID（跟节点为0）
    ///</summary>
    public string? ParentId { get;   set; } = "0";
    /// <summary>
    /// 菜单名称
    /// </summary>
    public string? Title { get;   set; }

    public string? ParentPath { get;   set; }

    /// <summary>
    /// 菜单名称
    /// </summary>
    public string? FullName { get;   set; }

    /// <summary>
    /// 菜单类型
    /// </summary>
    public string? Type { get;   set; }


    /// <summary>
    /// 是否为链接
    /// </summary>
    public string? IsLink { get;   set; }



    /// <summary>
    /// 路由
    /// </summary>
    public string? Route { get;   set; }


    /// <summary>
    /// 路由名称
    /// </summary>
    public string? RouteName { get;   set; }

    /// <summary>
    /// 重定向
    /// </summary>
    public string? Redirect { get;   set; }


    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get;   set; }



    /// <summary>
    /// 描述
    /// </summary>
    public string? Description { get;   set; }
    /// <summary>
    /// 按钮代码
    /// </summary>
   // public string? ButtonCode { get;   set; }
    public string? PermissionIdentity { get; set; }
    
    /// <summary>
    /// 组件路径
    /// </summary>
    public string? ComponentPath { get;   set; }
    ///// <summary>
    ///// 打开方式（null：框架页；_blank：新窗口打开）
    ///// </summary>
    //public string? Target { get;   set; }

    ///// <summary>
    ///// 是否展开
    ///// </summary>
    //public string? IsExpand { get;   set; }
    ///// <summary>
    ///// 是否启用
    ///// </summary>
    //public string?  EnableDmark { get;   set; }

    ///// <summary>
    ///// 是否删除
    ///// </summary>
    //public string?  DeleteMark { get;   set; }


    /// <summary>
    /// 创建卡号
    /// </summary>
    public string? CreateCardNumber { get;   set; }

    ///// <summary>
    ///// 创建日期
    ///// </summary>
    public DateTime CreateTime { get;   set; }

    ///// <summary>
    ///// 创建人
    ///// </summary>
    public string? CreateName { get;   set; }


    /// <summary>
    /// 创建卡号
    /// </summary>
    public string? UpdateCardNumber { get; set; }

    ///// <summary>
    ///// 创建日期
    ///// </summary>
    public DateTime UpdateTime { get; set; }

    ///// <summary>
    ///// 创建人
    ///// </summary>
    public string? UpdateName { get; set; }








    [SugarColumn(IsIgnore = true)]
    public List<Menu> Children { get; set; } = new List<Menu>();

    [Navigate(NavigateType.OneToOne, nameof(MenuId),nameof(MenuMeta.MenuId))]
    public MenuMeta? menuMeta { get;  set; }

    public static Menu Create(Menu menu)
    {
        if (menu is null) throw new ArgumentNullException("menu");
        menu.MenuId = SnowFlakeSingle.Instance.NextId().ToString();
        menu.CreateCardNumber = "9999";
        menu.CreateTime = DateTime.Now;
        menu.CreateName = "9999";
        menu.menuMeta = MenuMeta.Create(menu);
        return menu;
    }
    public static Menu Update(Menu menu)
    {
        if (menu is null) throw new ArgumentNullException("menu");
        //  menu.MenuId = SnowFlakeSingle.Instance.NextId().ToString();
        menu.ParentId = CheckParentId(menu);
        menu.UpdateCardNumber = "9999";
        menu.UpdateTime = DateTime.Now;
        menu.UpdateName = "9999";
        menu.menuMeta = MenuMeta.Update(menu);
        return menu;
    }

    public static string CheckParentId(Menu menu)
    => menu.MenuId == menu.ParentId ? "0" : menu.ParentId!;
           

    

}
